
//
//  PersonInfoViewController.m
//  hello mui
//
//  Created by zhangtao on 15/9/14.
//  Copyright (c) 2015年 zt.td. All rights reserved.
//

#import "PersonInfoViewController.h"
#import "NickNameViewController.h"
#import "SexViewController.h"
#import "PhoneNumViewController.h"
@interface PersonInfoViewController ()
@property (strong, nonatomic) IBOutlet UIButton *phoneNumBtn;
@property (strong, nonatomic) IBOutlet UIImageView *nickArrow;
@property (strong, nonatomic) IBOutlet UIImageView *sexArrow;
@property (strong, nonatomic) IBOutlet UIImageView *phoneArrow;
@property (strong, nonatomic) IBOutlet UILabel *phoneNumLabel;
@property (weak, nonatomic) IBOutlet UIView *a;
@property (weak, nonatomic) IBOutlet UIView *b;
@property (weak, nonatomic) IBOutlet UIView *c;

@end

@implementation PersonInfoViewController

//-(void)viewWillAppear:(BOOL)animated{
//    self.tabBarController.tabBar.hidden = YES;
//}

//-(void)viewWillDisappear:(BOOL)animated{
//    self.tabBarController.tabBar.hidden = NO;
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"个人信息";
//    
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
      self.view.backgroundColor = [UIColor colorWithRed:240/255.f green:240/255.f blue:240/255.f alpha:1];
    _nickName.text =  NSUSER_DEF(@"NICKNAME");
    _sex.text = NSUSER_DEF(@"GENER");
    NSLog(@"~~~~~~~~~~%@,%@",NSUSER_DEF(@"PHONE"),NSUSER_DEF(@"LOGINPHONE"));
    _phoneNumLabel.text = [self RangePhoneNum];  //NSUSER_DEF(@"PHONE");
    
    [self httpRequest];
    
    if ( ![self isChange]) {
        _nickArrow.hidden =
        _sexArrow.hidden =
        _phoneArrow.hidden =
        _phoneNumLabel.hidden =
        _phoneNumBtn.hidden = YES;
    }

    
    _a.layer.borderColor = _b.layer.borderColor = _c.layer.borderColor = rgb_box;
    _a.layer.borderWidth = _b.layer.borderWidth = _c.layer.borderWidth = 1;
    
    // Do any additional setup after loading the view from its nib.
}

-(void)httpRequest{
//    NSString *url = [NSString stringWithFormat:@"https://api.weixin.qq.com/sns/userinfo?access_token=%@&openid=%@", self.access_token, self.openid];
//    
//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//        NSURL *zoneUrl = [NSURL URLWithString:url];
//        NSString *zoneStr = [NSString stringWithContentsOfURL:zoneUrl encoding:NSUTF8StringEncoding error:nil];
//        NSData *data = [zoneStr dataUsingEncoding:NSUTF8StringEncoding];
//        dispatch_async(dispatch_get_main_queue(), ^{
//            if (data) {
//                NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
//                NSLog(@"openid = %@", [dic objectForKey:@"openid"]);
//                NSLog(@"nickname = %@", [dic objectForKey:@"nickname"]);
//                NSLog(@"sex = %@", [dic objectForKey:@"sex"]);
//                NSLog(@"country = %@", [dic objectForKey:@"country"]);
//                NSLog(@"province = %@", [dic objectForKey:@"province"]);
//                NSLog(@"city = %@", [dic objectForKey:@"city"]);
//                NSLog(@"headimgurl = %@", [dic objectForKey:@"headimgurl"]);
//                NSLog(@"unionid = %@", [dic objectForKey:@"unionid"]);
//                NSLog(@"privilege = %@", [dic objectForKey:@"privilege"]);
//                
//                AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
//                appdelegate.headimgurl = [dic objectForKey:@"headimgurl"]; // 传递头像地址
//                appdelegate.nickname = [dic objectForKey:@"nickname"]; // 传递昵称
//                //                NSLog(@"appdelegate.headimgurl == %@", appdelegate.headimgurl); // 测试
//                //                NSLog(@"appdelegate.nickname == %@", appdelegate.nickname);
//                [[NSNotificationCenter defaultCenter] postNotificationName:@"Note" object:nil]; // 发送通知
//            }
//        });
//    });
    
}

- (IBAction)nickNameBtn:(id)sender {
    if ( ![self isChange]) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"使用账号登陆本APP才能修改昵称" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alert show];
    }else{
    NickNameViewController *nick = [[NickNameViewController alloc]initWithNibName:@"NickNameViewController" bundle:nil];
    nick.infoVC = self;
    [self.navigationController pushViewController:nick animated:YES];
    }
}

- (IBAction)phoneNumBtn:(id)sender {
//    if (![self isChange]){
//        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"使用账号登陆本APP才能修改手机号" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
//        [alert show];
//    }
//    else{
//    PhoneNumViewController *phoneNumVC = [[PhoneNumViewController alloc]init];
//        phoneNumVC.infoVC = self;
//
//    [self.navigationController pushViewController:phoneNumVC animated:YES];
//    }
    
}

- (IBAction)sexBtn:(id)sender {
    if ( ![self isChange]) {
        ///
         UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"使用账号登陆本APP才能修改性别" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alert show];
    }else{
    SexViewController *sex = [[SexViewController alloc]initWithNibName:@"SexViewController" bundle:nil];
    sex.infoVC = self;
        
        
    [self.navigationController pushViewController:sex animated:YES];
       
    }
}

-(BOOL)isChange{
    BOOL bools = YES;
//    if ( [NSUSER_DEF(@"SHARE") isEqualToString:TENCENT_LOGIN]|| [NSUSER_DEF(@"SHARE") isEqualToString:WECHAT_LOGIN] ) {
//        bools = NO;
//    }else{
//        bools = YES;   //本app账号
//    }
    
    
    return bools;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(NSString *)RangePhoneNum{
    NSString *phonenum ;
    if ([NSString stringWithFormat:@"%@", NSUSER_DEF(@"PHONE")].length==11) {
    phonenum = NSUSER_DEF(@"PHONE");
    }else{
        phonenum = NSUSER_DEF(@"LOGINPHONE");
    }
    NSString *filstObj = [phonenum substringWithRange:NSMakeRange(0, 3)];
    NSString *lastObj = [phonenum substringWithRange:NSMakeRange(8, 3)];
    NSString *allPhoneNum = [[filstObj stringByAppendingString:@"******"] stringByAppendingString:lastObj];
    
    return allPhoneNum;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
